package com.hongawen.mqtt.service;

import lombok.RequiredArgsConstructor;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.stereotype.Service;


/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年11月23日 19:00
 */
@Service
@RequiredArgsConstructor
public class TopicService {

    private final MessageProducerSupport messageProducerSupport;



    /**
     * 添加主题
     */
    public void addTopic( String... topics) {
        MqttPahoMessageDrivenChannelAdapter adapter = (MqttPahoMessageDrivenChannelAdapter) messageProducerSupport;
        adapter.addTopic(topics);
    }

    /**
     * 删除主题
     */
    public void removeTopic( String... topics) {
        MqttPahoMessageDrivenChannelAdapter adapter = (MqttPahoMessageDrivenChannelAdapter) messageProducerSupport;
        adapter.removeTopic(topics);
    }

    /**
     * 获取所有的主题
     */
    public String[] getAllTopics() {
        MqttPahoMessageDrivenChannelAdapter adapter = (MqttPahoMessageDrivenChannelAdapter) messageProducerSupport;
        String[] topic = adapter.getTopic();
        return topic;
    }

}
